# -*- coding: utf8 -*-

import os
from google.appengine.ext.webapp import template

def render_to_response(response, template_name, context):
    if template_name[-4:] == '.xml':
        response.headers["Content-Type"] = "text/xml"
    else:
        response.headers["Content-Type"] = "text/html"

    from os.path import dirname
    path = os.path.join(dirname(dirname(__file__)), "templates", template_name)
    response.out.write(template.render(path, context))

def render_to_error(response, error_id, error_msg):
    context = {'error_id' : error_id, 'error_msg' : error_msg};
    return render_to_response(response, 'error.xml', context)

def render_to_success(response, success_msg):
    context = {'success_msg' : success_msg};
    return render_to_response(response, 'success.xml', context)
    
def not_login(response):
    pass